/**
 * [643] 子数组最大平均数 I
 *
 * @format
 * @lc app=leetcode.cn id=643 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var findMaxAverage = function (nums, k) {
    let sum = 0
    for (let i = 0; i < k; i++) sum += nums[i]
    let max = sum
    for (let i = 0; i < nums.length - k; i++) {
        sum -= nums[i]
        sum += nums[i + k]
        sum > max ? (max = sum) : null
    }
    return max / k
}
// debugger
// console.log(findMaxAverage([1, 12, -5, -6, 50, 3], 4))
// @lc code=end
